<template>
  <div>
    <div class="container">
      <div class="head">
        <div class="top">
          <div class="setting" @click="signout()">
            <van-icon name="delete" color="#fff" />
          </div>
        </div>
        <van-card
          :title="nick ? nick : '暂未设置昵称'"
          :desc="username"
          :thumb="
            avatarUrl
              ? avatarUrl
              : 'https://img0.baidu.com/it/u=1489807627,808259306&fm=26&fmt=auto'
          "
        >
          <template #tags>
            <van-tag plain type="danger">微信号：{{ wx }}</van-tag>
          </template>
          <template #footer>
            <van-icon name="arrow" color="#fff" @click="gosetting" />
          </template>
        </van-card>
        <van-grid :border="true" :gutter="0" :column-num="4">
          <van-grid-item icon="shopping-cart" text="购物车" to="/cart" />
          <van-grid-item icon="point-gift" text="收藏夹" to="/favor" />
          <van-grid-item icon="balance-list" text="订单" to="/order" />
          <van-grid-item icon="map-marked" text="收货地址" to="contactslist" />
        </van-grid>
      </div>
      <div class="maybe">
        <div class="style2">
          <div class="home-items">
            <div class="hi_container clearfix">
              <div class="mblove">你可能还需要</div>
              <div
                class="sy_none"
                v-if="items.length === 0"
                style="width：100%; font-size:0.4rem; text-align:center; margin-top:4rem"
              >
                该分类下没有商品
              </div>
              <div
                class="ht_cc"
                v-for="item in items"
                :key="item.id"
                @click="goDetail(item.id)"
              >
                <div class="ht_cc_img">
                  <img :src="item.pic" />
                </div>
                <div class="ht_cc_msg">
                  <p class="ht_cc_msg_title">{{ item.name }}</p>
                  <p class="ht_cc_msg_msg">
                    {{ item.characteristic ? item.characteristic : '暂无描述' }}
                  </p>
                </div>
                <div class="ht_cc_shopping clearfix">
                  <span class="price">￥ {{ item.minPrice }}</span>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <my-tabbar></my-tabbar>
  </div>
</template>

<script>
import MyTabbar from '../../components/tabbar.vue'
import { goodslist, getusermsg } from '_api'
import { getToken } from '_utils/token.js'
import { Dialog, Toast } from 'vant'
export default {
  data () {
    return {
      items: [],
      wx: '',
      username: '',
      nick: '',
      avatarUrl: ''
    }
  },
  components: { MyTabbar },
  created () {
    this.homegoodlist()
    this.getusermsg()
  },
  methods: {
    homegoodlist () {
      goodslist({
        categoryId: this.$route.query.cateId,
        orderBy: this.orderBy
      }).then((res) => {
        console.log(res)
        if (res.data.code === 0) {
          this.items = res.data.data.result
        }
      })
    },
    goDetail (id) {
      this.$router.push(`/details/${id}`)
    },
    getusermsg () {
      getusermsg({
        token: getToken()
      }).then((res) => {
        console.log(res)
        this.wx = res.data.data.base.wx
        this.username = res.data.data.base.username
        this.nick = res.data.data.base.nick
        this.avatarUrl = res.data.data.base.avatarUrl
        console.log(this.avatarUrl)
      })
    },
    gosetting () {
      this.$router.push('/settinguser')
    },
    signout () {
      Dialog.confirm({
        message: '退出？'
      }).then(() => {
        this.$router.push('/login')
        localStorage.setItem('token', '')
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.container {
  box-sizing: border-box;
  background: rgb(236, 236, 236);
  .head {
    background: linear-gradient(0deg, #ff344d, #ff6f81);
    padding: 0.2rem 0.2rem 0.4rem;
    box-sizing: border-box;
    .top {
      width: 100%;
      text-align: right;
      .van-icon {
        font-size: 0.4rem;
      }
    }
    /deep/ .van-card {
      background: none;
      .van-image {
        border-radius: 100%;
        overflow: hidden;
        img {
          width: 1.6rem;
          height: 1.6rem;
          border-radius: 100%;
          padding: 2px;
          border: 1px solid #fff;
        }
      }
      .van-card__content {
        margin-left: 0.1rem;
        .van-card__title.van-multi-ellipsis--l2 {
          font-size: 0.34rem;
          color: #fff;
          line-height: 0.6rem;
        }
        .van-card__desc {
          font-size: 0.28rem;
          color: #fff;
          line-height: 0.5rem;
        }
        .van-tag--plain {
          margin-top: 0.15rem;
          background: none;
          color: #fff;
        }
      }
      .van-card__footer {
        position: absolute;
        right: 0.06rem;
        bottom: 50%;
        font-size: 0.46rem;
      }
    }
    .van-grid {
      position: absolute;
      left: 50%;
      width: 90%;
      transform: translateX(-50%);
      border-radius: 0.15rem;
      overflow: hidden;
    }
  }
}
.style2 {
  padding: 1.8rem 0.3rem 1.2rem;
  border-radius: 0.2rem;
  overflow: hidden;
  .hi_container {
    width: 100%;
    background: #fff;
    border-radius: 0.2rem;
    overflow: hidden;
    .mblove {
      padding-top: 0.3rem;
      line-height: 0.7rem;
      font-size: 0.32rem;
      font-weight: bold;
      text-align: center;
    }
    .ht_cc {
      box-shadow: -1px 1px 4px #999;
      display: inline-block;
      height: 5.8rem;
      overflow: hidden;
      border-radius: 0.2rem;
      width: 46%;
      background: #fff;
      margin: 0.2rem 2%;
      .ht_cc_img {
        width: 100%;
        img {
          width: 100%;
          height: 3.3rem;
        }
      }
      .ht_cc_msg {
        padding: 0.15rem;
        .ht_cc_msg_title {
          font-weight: 700;
          color: #000;
          font-size: 0.28rem;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
          line-height: 0.6rem;
        }
        .ht_cc_msg_msg {
          height: 0.92rem;
          word-break: break-all;
          text-overflow: ellipsis;
          overflow: hidden;
          display: -webkit-box;
          -webkit-line-clamp: 2;
          -webkit-box-orient: vertical;
          color: #666;
          font-size: 0.26rem;
          line-height: 0.46rem;
        }
      }
      .ht_cc_shopping {
        padding: 0.15rem;
        .price {
          float: left;
          font-size: 0.36rem;
          line-height: 0.45rem;
          color: red;
        }
        .add_cart {
          float: right;
          font-size: 0.36rem;
          line-height: 0.45rem;
        }
      }
    }
  }
}
</style>
